package main

import (
	"encoding/base64"
	"log"
	"os"
)

func main() {
	file, err := os.Open("/Users/lizhe/GolandProjects/TestProject/base64/1.JPG")
	if err != nil {
		log.Fatalln(err)
	}
	defer file.Close()

	// FileInfo:
	stats, err := file.Stat()
	if err != nil {
		log.Fatalln(err)
	}

	// []byte
	data := make([]byte, stats.Size())
	file.Read(data)
	result := base64.StdEncoding.EncodeToString(data)
	print(result)

	base64File, err := os.Create("/Users/lizhe/GolandProjects/TestProject/base64/base64.txt")
	defer base64File.Close()

	base64File.Write([]byte(result))

	base64File.Sync()
}
